package com.tianhe.visitormanagement.server.impl;


import com.tianhe.visitormanagement.server.common.TCPServer;
import com.tianhe.visitormanagement.server.common.UdpHandlerAbstract;
import com.tianhe.visitormanagement.server.common.UdpServer;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * 设备Socket服务端
 *
 * @author ：dongchao
 * @date ：Created in 2020/1/24 8:45
 */
@Data
@Component
public class ServerSocketRun implements CommandLineRunner {
    private final static Logger LOGGER = LoggerFactory.getLogger(ServerSocketRun.class);

    @Autowired
    private VisitorServerSocket visitorServerSocket;

    @Autowired
    private RfidServerSocket rfidServerSocket;

    @Autowired
    private UdpServer udpServer;

    @Autowired
    private TCPServer tcpServer;

    @Autowired
    private RfidTCPHandlerImpl rfidTCPHandler;
    @Autowired
    private VisitorTCPHandlerImpl visitorTCPHandler;

    @Autowired
    private UdpHandlerAbstract udpHandlerAbstract;




    @Override
    public void run(String... args) {
        new Thread(() -> {
            visitorServerSocket.startAction();
        }).start();

//        new Thread(() -> {
//            rfidServerSocket.startAction(2009);
//        }).start();

        /**
         * 启动RFID服务端
         */
        new Thread(() -> {
            tcpServer.run(2020,rfidTCPHandler);
        }).start();

        /**
         * 启动访客机服务端
         */
        new Thread(() -> {
            tcpServer.run(2022,visitorTCPHandler);
        }).start();

        new Thread(() -> {
            udpServer.run(5000,udpHandlerAbstract);
        }).start();

    }
}
